import Constants from '../const'
import ObjectUtils from "@/methods/ObjectUtils"
import Token from "@/methods/Token"
import BalaBala from "@/methods/BalaBala"
import axios from "@/plugins/axios"
import Cookies from 'js-cookie'
import RouterUtils from "@/methods/RouterUtils"
import RouterName from "@/const/RouterName"
import ImgUtils from "@/methods/ImgUtils"
import CommonStatusEnum from "@/const/CommonStatusEnum"

export default (Vue) => {
  Vue.prototype.$const = Constants
  Vue.prototype.$commonStatus = Constants.commonStatus
  Vue.prototype.$commonStatusEnum = Constants.commonStatusEnum
  Vue.prototype.$routerName = RouterName
  Vue.prototype.$routerTo = RouterUtils.routerTo
  Vue.prototype.$goBack = RouterUtils.goBack
  Vue.prototype.$obj = ObjectUtils
  Vue.prototype.$img = ImgUtils
  Vue.prototype.$blbl = BalaBala
  Vue.prototype.$info = BalaBala.info
  Vue.prototype.$warning = BalaBala.warning
  Vue.prototype.$error = BalaBala.error
  Vue.prototype.$token = Token
  Vue.prototype.$axios = axios
  Vue.prototype.$post = axios.post
  Vue.prototype.$Cookies = Cookies
  Vue.prototype.$imgUrl = ImgUtils.imgUrl
  Vue.prototype.$getTalkLargeImgUrl = ImgUtils.getTalkLargeImgUrl
  Vue.prototype.$getTalkSmallImgUrl = ImgUtils.getTalkSmallImgUrl
  Vue.prototype.$imgUrl = ImgUtils.imgUrl
  Vue.prototype.$websocketUrl = process.env.VUE_APP_BASE + 'webSocketServer/'
  Vue.prototype.$authCodeInterval = Number(process.env.VUE_APP_AUTH_CODE_INTERVAL)
  Vue.prototype.$deleteNotNum = (val: string) => {
    return val.replace(Constants.regNotNum, '')
  }

  // 注册一个全局自定义指令 `v-focus`
  Vue.directive('focus', {
    // 当被绑定的元素插入到 DOM 中时……
    update: (el, {value, oldValue}) => {
      if (value) {
        //必须值改变了才重新获得焦点
        if (value !== oldValue) {
          el.querySelector('input').focus()
        }
      }
    }
  })
}
